package com.shilei.cor;

import com.shilei.GameObject;

import java.util.LinkedList;
import java.util.List;

/**
 * @description: 碰撞比较链
 * @author: 81271
 * @date: 2020-04-15 20:56
 */
public class ColliderChain implements Collider{
    private List<Collider> colliderList = new LinkedList<>();


    public ColliderChain() {
        add(new TankBulletCollider());
        add(new TankTankCollider());
        add(new TankWallCollider());
        add(new BulletWallCollider());
    }

    private void add(Collider collider) {
        colliderList.add(collider);
    }

    @Override
    public boolean collide(GameObject go1, GameObject go2) {
        for (Collider collider : colliderList) {
            if (collider.collide(go1, go2)) {
                break;
            }
        }
        return true;
    }

}
